package com.wzdigit.wms.basic.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
	
	public final static String FORMATTEXT01 = "HH:mm";
	public final static String FORMATTEXT02 = "yyyyMMdd";
	public final static String FORMATTEXT03 = "yyyy/MM/dd";
	public final static String FORMATTEXT04 = "yyyy/MM/dd HH:mm:ss";
	public final static String FORMATTEXT05 = "yyyy-MM-dd HH:mm:ss";
	public final static String FORMATTEXT06 = "yyyy-MM-dd HH:mm:ss:SSS";

	/**
	 * 格式化时间
	 * 
	 * @param date
	 * @param format
	 * @return
	 */
	public static String format(Date date, String format) {
		return new SimpleDateFormat(format).format(date);
	}
	public static String format(long timestamp, String format) {
		return new SimpleDateFormat(format).format(new Date(timestamp));
	}

	/**
	 * 去除date时分秒
	 * 
	 * @param date
	 * @return
	 */
	public static Date getStartTime(Date date) {
		Calendar todayEnd = Calendar.getInstance();
        todayEnd.setTimeInMillis(date.getTime());
        todayEnd.set(Calendar.HOUR_OF_DAY, 00);
        todayEnd.set(Calendar.MINUTE, 00);
        todayEnd.set(Calendar.SECOND, 00);
        todayEnd.set(Calendar.MILLISECOND, 000);
        return todayEnd.getTime();
	}
	public static Date getStartTime(long timeStamp) {
		Calendar todayEnd = Calendar.getInstance();
        todayEnd.setTimeInMillis(timeStamp);
        todayEnd.set(Calendar.HOUR_OF_DAY, 00);
        todayEnd.set(Calendar.MINUTE, 00);
        todayEnd.set(Calendar.SECOND, 00);
        todayEnd.set(Calendar.MILLISECOND, 000);
        return todayEnd.getTime();
	}
	
	/**
	 * 获取date结束时间
	 * 
	 * @param date
	 * @return
	 */
	public static Date getEndTime(Date date) {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.setTime(date);
        todayEnd.set(Calendar.HOUR_OF_DAY, 23);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MILLISECOND, 999);
        return todayEnd.getTime();
    }
	public static Date getEndTime(long timeStamp) {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.setTime(new Date(timeStamp));
        todayEnd.set(Calendar.HOUR_OF_DAY, 23);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MILLISECOND, 999);
        return todayEnd.getTime();
    }
}
